package com.example.swordjava;


import java.util.ArrayList;

public class Test35 {

    public static void main(String[] args) {

        int[][] a = {{1, 2, 3, 4},
                {5, 6, 7, 8},
                {9, 10, 11, 12},
                {13, 14, 15, 16}};

        System.out.println(a[0][1]);

    }

    public class RandomListNode {
        int label;
        RandomListNode next = null;
        RandomListNode random = null;

        RandomListNode(int label) {
            this.label = label;
        }
    }

    /**
     * 复杂链表的复制
     * 输入一个复杂链表（每个节点中有节点值，以及两个指针，一个指向下一个节点，另一个特殊指针random指向一个随机节点），请对此链表进行深拷贝，并返回拷贝后的头结点。
     */

    public RandomListNode Clone(RandomListNode pHead) {
        if (pHead == null) return null;
        RandomListNode cur = pHead;
        while (cur != null) {
            RandomListNode randomListNode = new RandomListNode(cur.label);
            RandomListNode next = cur.next;
            cur.next = randomListNode;
            randomListNode.next = next;
            cur = next;
        }
        cur = pHead;
        while (cur != null) {
            RandomListNode cloneNode = cur.next;
            cloneNode.random = cur.random==null?null:cur.random.next;
            cur = cur.next.next;
        }
        cur = pHead;
        RandomListNode newHead = cur.next;
        while (cur != null) {
            RandomListNode cloneHead = cur.next;
            cur.next = cloneHead.next;
            cloneHead.next = cloneHead.next == null ? null : cloneHead.next.next;
            cur = cur.next;
        }
        return newHead;
    }
}
